<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Comment_model extends CI_Model {
    
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
        $this->load->database(); 
    }
    
	function show_all_comment($num,$offset){
		$this->load->database();
		$this->db->order_by("id", "desc"); 
		$query=$this->db->get('tbcomment',$num,$offset);
		if ($query->num_rows() > 0)
		{
			return $query->result();
		}
		return $query->result();
	}
	
	function show_all_comment_by_id($id){
		$this->load->database();
		$this->db->order_by("id", "desc"); 
		$this->db->where('postid',$id);
		 
		$query=$this->db->get('tbcomment');
		 
		if ($query->num_rows() > 0)
		{
			return $query->result();
		}
		return $query->result();
	}
 
	function add_comment($postid,$userid,$content){ 
		$this->load->database();
    	$data = array( 
            'postid'=>$postid,
            'userid'=>$userid,
    		'content'=>$content, 
    		'createtime'=>date("d-m-Y h:i:s")
            );
    	$this->db->insert('tbcomment', $data); 
	}
	
	 
	 
	
	function total_comment_by_id($id){  
    	$this->load->database();
    	$this->db->where('id',$id);
		return $this->db->count_all('tbcomment'); 
	}
	
 
	function del_comment($id){ 
		$this->load->database();
		$this->db->where('id', $id);
		$this->db->delete('tbcomment'); 
	}
}
    ?>